package com.hrms.hrms_employee.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hrms.common.vo.PageVo;
import com.hrms.common.vo.ResultMessage;
import com.hrms.hrms_employee.entity.StaffPosition;
import com.hrms.hrms_employee.service.StaffPositionService;
import com.hrms.hrms_employee.vo.AccountUser;
import com.hrms.hrms_employee.vo.staffPostionDetailVO;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 员工职位表(StaffPosition)表控制层
 *
 * @author makejava
 * @since 2025-01-17 16:55:59
 */
@RestController
@RequestMapping("staffPosition")
public class StaffPositionController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private StaffPositionService staffPositionService;

    /**
     * 查询员工详细数据
     *员工职位，员工个人信息，员工合同信息
     * @param
     * @param
     * @return
     */
    @GetMapping("/{id}")
    public ResultMessage selectDetail(@PathVariable Long id) {
//        RequestUtil requestUtil = new RequestUtil();
//        Map<String, String> map = requestUtil.getParameterMap(request);
        // 获取当前用户信息
//        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//        AccountUser user = (AccountUser) auth.getPrincipal();
        staffPostionDetailVO positionPage = this.staffPositionService.pageInfo(id);
        return new ResultMessage(ResultMessage.Success,"",positionPage);
    }

    /**
     * 查询员工list数据
     *
     * @param
     * @param
     * @return
     */
    @GetMapping
    public ResultMessage selectAll(PageVo pageVo, StaffPosition staffPosition) {
        Page<StaffPosition> page = new Page<>(pageVo.getCurrent(), pageVo.getSize());
        Page<StaffPosition> positionPage = this.staffPositionService.page(page, new QueryWrapper<>(staffPosition));
        return new ResultMessage(ResultMessage.Success,"",positionPage);
    }


    /**
     * 新增修改数据
     *
     * @param staffPosition 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ResultMessage insert(@RequestBody StaffPosition staffPosition) {
        this.staffPositionService.save(staffPosition);
        return new ResultMessage(ResultMessage.Success,"");
    }
    /**
     * 根据id新增修改数据
     *
     * @param
     * @return 新增结果
     */
    @PostMapping("/update")
    public ResultMessage update(@RequestParam String id) {
        this.staffPositionService.update(new UpdateWrapper<StaffPosition>().set("state",1).eq("id",Long.parseLong(id)));
        return new ResultMessage(ResultMessage.Success,"");
    }
    /**
     * 根据stationId（岗位id）查询部门员工以及下级部门员工
     */
    @GetMapping("/department")
    public ResultMessage selectDepartmentStaffs(@RequestParam Long stationId) {
        List<StaffPosition> positionList = this.staffPositionService.selectDepartmentStaffs(stationId);
        return new ResultMessage(ResultMessage.Success,"",positionList);
    }
    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ResultMessage delete(@RequestParam("idList") Long id) {
        this.staffPositionService.removeById(id);
        return new ResultMessage(ResultMessage.Success,"");
    }

    /**
     * staff_id（岗位id）查询部门员工信息
     */
    @GetMapping("/position")
    public ResultMessage position(@RequestParam Long id) {
        StaffPosition position = this.staffPositionService.position(id);
        return new ResultMessage(ResultMessage.Success,"",position);
    }
}

